package org.jeecg.modules.demo.jxcx.controller;



import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.jxcx.Utils.R;
import org.jeecg.modules.demo.jxcx.po.JxcOpenuser;
import org.jeecg.modules.demo.jxcx.service.JxcOpenuserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * (JxcOpenuser)表控制层
 *
 * @author makejava
 * @since 2024-07-23 18:08:55
 */
@RestController
@RequestMapping("jxcOpenuser")
public class JxcOpenuserController{
    private static Logger logger = LoggerFactory.getLogger(JxcOpenuserController.class);
    /**
     * 服务对象
     */
    @Resource
    private JxcOpenuserService jxcOpenuserService;

    @PostMapping("/quit")
    @ResponseBody
    public R getDefault(@RequestBody JSONObject params){
        R result = null;
        try {
            JSONObject json = new JSONObject();
            jxcOpenuserService.updateIsDefult(params.getString("account"),params.getString("openid"));
            json.put("code",200);
            json.put("data","退出成功");
            json.put("msg","success");
            result = new R().ok(json);
        } catch (Exception e) {
            result = new R().error(e.getMessage());
        }
        return result;
    }
    @PostMapping("/queryall")
    @ResponseBody
    public R queryall(@RequestBody JSONObject params) {
        String companyId = params.getString("companyId");
        return new R().ok(jxcOpenuserService.getByConpanyId(companyId));
    }
    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param jxcOpenuser 查询实体
     * @return 所有数据
     */
    @GetMapping
    public R selectAll(Page<JxcOpenuser> page, JxcOpenuser jxcOpenuser) {
        return new R().ok(this.jxcOpenuserService.page(page, new QueryWrapper<>(jxcOpenuser)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return new R().ok(this.jxcOpenuserService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param jxcOpenuser 实体对象
     * @return 新增结果
     */
    @PostMapping("add")
    public R insert(@RequestBody JxcOpenuser jxcOpenuser) {
        return new R().ok(this.jxcOpenuserService.save(jxcOpenuser));
    }

    /**
     * 修改数据
     *
     * @param jxcOpenuser 实体对象
     * @return 修改结果
     */
    @PutMapping("update")
    public R update(@RequestBody JxcOpenuser jxcOpenuser) {
        return new R().ok(this.jxcOpenuserService.updateById(jxcOpenuser));
    }

    /**
     * 删除数据
     *
     * @param
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestBody JSONObject params) {
        JSONArray idList = params.getJSONArray("idList");
        logger.info("删除数据"+idList);
        return new R().ok(this.jxcOpenuserService.removeByIds(idList));
    }
}

